| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.emojiLog = exports.emojiLogError = exports.emojiLogWarn = exports.emojiLogInfo = exports.NAME_EXTENSION = exports.NAME_SAMPLEFOLDER = exports.NAME_STOREFOLDER = exports.stringifyWithLevel = void 0;
- /**
- * 自定义 JSON.stringify,支持按层级输出
- * @param {any} data 要序列化的数据
- * @param {number} maxLevel 最大层级深度(默认全部展开)
- * @param {number | undefined} space 格式化空格数(默认不格式化)
- * @returns {string} 序列化后的 JSON 字符串
- */
- function stringifyWithLevel(data, maxLevel = Infinity, space) {
- // 定义替换函数的类型
- const replacer = function (key, value) {
- var _a;
- // 获取当前值的层级(通过递归调用栈的深度计算)
- const level = (_a = this === null || this === void 0 ? void 0 : this.level) !== null && _a !== void 0 ? _a : 0;
- // 如果超过最大层级深度,则简略显示对象
- if (level >= maxLevel && typeof value === 'object' && value !== null) {
- return '[Object]';
- }
- // 继续递归时传递层级信息
- if (typeof value === 'object' && value !== null) {
- return Object.assign(Object.assign({}, value), { level: level + 1 });
- }
- return value;
- };
- // 返回序列化结果
- return JSON.stringify(data, replacer, space);
- }
- exports.stringifyWithLevel = stringifyWithLevel;
- exports.NAME_STOREFOLDER = 'curvetexture';
- exports.NAME_SAMPLEFOLDER = 'curvetexture-sample';
- exports.NAME_EXTENSION = 'curvetexture2d';
- function emojiLogInfo(keystr, ...optionalParams) {
- emojiLog(0, keystr, ...optionalParams);
- }
- exports.emojiLogInfo = emojiLogInfo;
- function emojiLogWarn(keystr, ...optionalParams) {
- emojiLog(1, keystr, ...optionalParams);
- }
- exports.emojiLogWarn = emojiLogWarn;
- function emojiLogError(keystr, ...optionalParams) {
- emojiLog(2, keystr, ...optionalParams);
- }
- exports.emojiLogError = emojiLogError;
- function emojiLog(t, keystr, ...optionalParams) {
- const emojis = ['✅', '❗️', '❌'];
- const inf = Editor.I18n.t(`${exports.NAME_EXTENSION}.${keystr}`);
- if (!inf || inf.length < 1) {
- console.warn('emojiLog key error: ', keystr);
- }
- console.log(`${exports.NAME_EXTENSION} ${emojis[t]} `, inf, ...optionalParams);
- }
- exports.emojiLog = emojiLog;
|